package job.sanyi;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Author: Zhang Dongwei
 * Date: 2023/8/16 13:39
 */
public class sy2 {
    public static void main(String[] args) {
        int[][] grid = new int[5][8];
        grid[0] = new int[]{1, 1, 1, 1, 1, 1, 1, 0};
        grid[1] = new int[]{1, 0, 0, 0, 0, 1, 1, 0};
        grid[2] = new int[]{1, 0, 1, 0, 1, 1, 1, 0};
        grid[3] = new int[]{1, 0, 0, 0, 0, 1, 0, 1};
        grid[4] = new int[]{1, 1, 1, 1, 1, 1, 1, 0};
//        for (int i = 0; i < grid.length; i++){
//            System.out.println(Arrays.toString(grid[i]));
//        }
        System.out.println(closedIsland(grid));
    }
    public static int closedIsland (int[][] grid) {
        int count = 0;
        for (int i = 1; i < grid.length - 1; i++){
            for (int j = 1; j < grid[0].length - 1; j++){
                if (grid[i][j] == 1) continue;
                if (grid[i - 1][j] == 1 && grid[i-1][j] == 1 && grid[i][j-1] == 1 && grid[i][j + 1] == 1){
                    count ++;
                }
            }
        }
        return count;
    }
}
